﻿package mortal.game.view.signUp.lineOn
{
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.signUp.*;
    import mortal.game.view.signUp.lineOn.data.*;
    import mortal.mvc.core.*;

    public class LineOnRewardController extends Controller
    {
        private var _lineOnModule:SignUpModule;
        private var _lineOnCache:LineOnRewardCache;
        private var _lineProxy:LineOnRewardProxy;
        private var _closeTime:uint = 0;
        private var _timeD:int = 2000;

        public function LineOnRewardController()
        {
            this._lineOnCache = Cache.instance.lineOn;
            this._lineProxy = GameProxy.lineOn;
            return;
        }// end function

        public function setView(param1:SignUpModule) : void
        {
            this._lineOnModule = param1;
            return;
        }// end function

        public function onShow(event:Event) : void
        {
            this.addEvents(true);
            return;
        }// end function

        public function onClose(event:Event) : void
        {
            this.addEvents(false);
            return;
        }// end function

        override protected function initServer() : void
        {
            EventUtil.addNetEvent(ServerCommand.NewDayUpdate, this.newDayUpdate, true);
            return;
        }// end function

        private function addEvents(param1:Boolean) : void
        {
            EventUtil.addSelfEvent(EventName.LineOnInitData, this.initData, param1);
            EventUtil.addSelfEvent(EventName.LineOnUpdateOneData, this.updateOneCell, param1);
            EventUtil.addSelfEvent(EventName.LineOnUpdateGetRewardCk, this.getRewardHd, param1);
            EventUtil.addSelfEvent(EventName.LineOnUpdateOneData, this.onGetBackHd, param1);
            EventUtil.addSelfEvent(EventName.LineOnCellRightScrollOne, this.scrollRightOne, param1);
            EventUtil.addSelfEvent(EventName.LineOnCellGetGoodTip, this.getGoodTip, param1);
            return;
        }// end function

        private function newDayUpdate(param1:Object) : void
        {
            Cache.instance.lineOn.toZeroHd();
            return;
        }// end function

        private function initData(param1:Object) : void
        {
            if (this._lineOnModule && this._lineOnModule.lineOnGiftPanel && this._lineOnModule.lineOnGiftPanel.uiLoadComplete)
            {
                this._lineOnModule.lineOnGiftPanel.initCells();
            }
            return;
        }// end function

        private function getRewardHd(param1:Object) : void
        {
            if (this._lineProxy)
            {
                this._lineProxy.getOnLineReward();
            }
            return;
        }// end function

        private function onGetBackHd(param1:Object) : void
        {
            var _loc_2:int = 0;
            if (this._lineOnModule && this._lineOnModule.lineOnGiftPanel && this._lineOnModule.lineOnGiftPanel.isDisposed == false)
            {
                if (AutoGuideCache.isGuideFuncPanel && this._lineOnModule.lineOnGiftPanel._rewardListPanel.hasGift() == false)
                {
                    if (this._closeTime != 0)
                    {
                        clearTimeout(this._closeTime);
                        this._closeTime = 0;
                    }
                    this._closeTime = setTimeout(this.onCloseWin, this._timeD);
                    return;
                }
                _loc_2 = Cache.instance.role.entityInfo.level;
                if (_loc_2 <= 30)
                {
                    if (this._lineOnModule.lineOnGiftPanel._rewardListPanel.hasGift() == false)
                    {
                        if (this._closeTime != 0)
                        {
                            clearTimeout(this._closeTime);
                            this._closeTime = 0;
                        }
                        this._closeTime = setTimeout(this.onCloseWin, this._timeD);
                        return;
                    }
                }
                if (Cache.instance.signUp.hasRewardToGet() == false)
                {
                    if (this._closeTime != 0)
                    {
                        clearTimeout(this._closeTime);
                        this._closeTime = 0;
                    }
                    this._closeTime = setTimeout(this.onCloseWin, this._timeD);
                    return;
                }
            }
            return;
        }// end function

        private function onCloseWin() : void
        {
            clearTimeout(this._closeTime);
            this._closeTime = 0;
            GameController.signUp.view.hide();
            return;
        }// end function

        private function updateOneCell(param1:Object) : void
        {
            if (this._lineOnModule && this._lineOnModule.lineOnGiftPanel && this._lineOnModule.lineOnGiftPanel.uiLoadComplete)
            {
                this._lineOnModule.lineOnGiftPanel.updateOneCell(param1.data);
            }
            return;
        }// end function

        private function scrollRightOne(param1:Object) : void
        {
            if (this._lineOnModule && this._lineOnModule.lineOnGiftPanel && this._lineOnModule.lineOnGiftPanel.uiLoadComplete)
            {
                this._lineOnModule.lineOnGiftPanel.scrollRightOne();
            }
            return;
        }// end function

        private function getGoodTip(event:DataEvent) : void
        {
            var _loc_2:* = event.data as String;
            Cache.instance.lineOn.getGodTips = _loc_2;
            return;
        }// end function

    }
}
